<?PHP
// vim: set expandtab tabstop=4 shiftwidth=4:
// +----------------------------------------------------------------------+
// | SAPID CMS                               		  					  |
// +----------------------------------------------------------------------+
// | Author:  Dmitry Sheiko (www.cmsdevelopment.com)	                  |
// | Copyright (c) 2004 Dmitry Sheiko	                                  |
// | http://sapid.sourceforge.net	                                      |
// +----------------------------------------------------------------------+
// | This source file is free software; you can redistribute it and/or    |
// | modify it under the terms of the GNU Lesser General Public           |
// | License as published by the Free Software Foundation; either         |
// | version 2.1 of the License, or (at your option) any later version.   |
// |                                                                      |
// | This source file is distributed in the hope that it will be useful,  |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    |
// | Lesser General Public License for more details.                      |
// +----------------------------------------------------------------------+
// Release: 08.11.04 (dd/mm/yy)
// $Id: seo_analizer.php,v 1.4 2006/02/20 08:39:46 sheiko Exp $


//Cut off lost picture requests
if (preg_match("/\.[gjpi][ipnc][fgo]/i", $_SERVER['REQUEST_URI'])) exit;
include ("../../etc/rc.conf.php");

if (!defined("SAPID_STARTED")) die("Hacking attempt!");
		$env["argv"][0] = "analizer";
		$_GET["paction"]="seoanalizer";
include(ROOT_PATH . "etc/rc.d/debug.inc.php");

include("../../etc/startup.inc.php");

		$env["page"]["TEMPLATE"] = $_GET["template"];
		$env["page"]["ID"] = $_GET["docid"];

$xmldata = getXMLdata(ROOT_PATH."usr/xml/content/".$env["page"]["ID"].".xml");
if($xmldata) {
	foreach($xmldata as $fetch) {
		if($fetch) {
			foreach($fetch as $key => $val) {
				$env["page.".$key] = $val;
				$env["page.".strtolower($key)] = $val;
			}
		}
	}
}
	

$sapi_obj = new sapi_parser(ROOT_PATH . "usr/templates/" . $env["page"]["TEMPLATE"]);
$parse = $sapi_obj->build_page();


$keywords = $env["page.METATITLE"]." ".$env["page.METADESCRIPTION"]." ".$env["page.METAKEYWORDS"];
$keywords = preg_replace("/[,\.]/"," ", $keywords);
$keywords = preg_replace("/[\/\{\}\[\]\^\$]/","", $keywords);
$keywords_arr = split(" ", $keywords);

$keywords_arr = array_unique($keywords_arr);

if($keywords_arr) {
	foreach($keywords_arr as $k => $v) {
		if(!$v) unset($keywords_arr[$k]);
		if(!preg_match("/\w/", $v))  unset($keywords_arr[$k]);
	}
}
print '<html>
<head>
<title>SEO Optimization</title>
<link rel="stylesheet" type="text/css" href="'.$http_path.'usr/system/default.css">
<body>';

if($keywords_arr) {
print '<div style="padding: 15px 5px 5px 5px" class="panel"><b>'.$lang["TableOfOftenWords"].'</b></div><br />
<table width="100%" cellpadding="0" cellspacing="0" border="0" style="font-family: Tahoma, Arial; font-size: 11px;" class="tpanel" >
	<tr>
		<td class="header">Index keywords</td>
		<td class="header" title="'.$lang["META-TITLE"].'"><sup>m</sup>Title</td>
		<td class="header" title="'.$lang["META-DESCRIPTION"].'"><sup>m</sup>Description</td>
		<td class="header" title="'.$lang["META-KEYWORDS"].'"><sup>m</sup>Keywords</td>
		<td class="header" title="Body of document">Body</td>
		<td class="header" title="Headers of document">&lt;H..&gt;</td>
		<td class="header" title="Links of document">&lt;A&gt;</td>
		<td class="header" title="Bolds of document">&lt;B&gt;</td>
	</tr>';

foreach($keywords_arr as $word) {

	@preg_match_all("/".$word."\s/is", $env["page.METATITLE"], $arr);	
	$title_c = count($arr[0]);
	@preg_match_all("/".$word."\s/is", $env["page.METADESCRIPTION"], $arr);	
	$desc_c = count($arr[0]);
	@preg_match_all("/".$word."\s/is", $env["page.METAKEYWORDS"], $arr);	
	$keywords_c = count($arr[0]);
	@preg_match_all("/".$word."\s/is", $parse, $arr);	
	$body_c = count($arr[0]);
	@preg_match_all("/<H?>.*?".$word.".*?<\/H?>\s/is", $parse, $arr);	
	$h_c = count($arr[0]);
	@preg_match_all("/<A?>.*?".$word.".*?<\/A>\s/is", $parse, $arr);	
	$a_c = count($arr[0]);
	@preg_match_all("/<B>.*?".$word.".*?<\/B>\s/is", $parse, $arr);	
	$b_c = count($arr[0]);	

print '<tr>
		<td>'.$word.'</td>
		<td align="center">'.$title_c.'</td>
		<td align="center">'.$desc_c.'</td>
		<td align="center">'.$keywords_c.'</td>
		<td align="center">'.$body_c.'</td>
		<td align="center">'.$h_c.'</td>
		<td align="center">'.$a_c.'</td>
		<td align="center">'.$b_c.'</td>
	</tr>';
}

print '</table>
<br />
<div align="center"><input type="button" onclick="window.close();" class="sapidcms_cont_btn" name="insertexp" value="'.$lang["CloseWindow"].'"></div>';
}
//print $parse;
print '</body></html>';
?>